<template>
  <div class="green-main">
    <div class="green-main-header" :style="setbackimg()"></div>
    <!-- 左边温度计展示 -->
    <div class="left-data">
      <!-- @/assets/environment-data/PH.png -->
      <img :src="cardmessage.src" width="40px" />
    </div>
    <!-- 中间数据展示 -->
    <div class="center-data">
      <div class="data-one">{{ cardmessage.ta }}{{ cardmessage.unit }}</div>
      <div class="data-two">{{ cardmessage.tb }}</div>
      <!-- <el-tooltip class="item" :content="`Bottom Center ${cardmessage.tc}`" placement="bottom">
        <div class="data-three">{{ cardmessage.tc }}</div>
      </el-tooltip> -->
      <el-tooltip :content="`${cardmessage.tc}`" placement="bottom" effect="light">
        <div class="data-three">{{ cardmessage.tc }}</div>
      </el-tooltip>
    </div>
    <!-- 右侧动态百分比 -->
    <div class="right-data">
      <div class="ani">
        <i v-if="cardmessage.jiantoutype === 1" class="el-icon-top animation"></i>
        <i v-else-if="cardmessage.jiantoutype === 3" class="el-icon-bottom animation"></i>
        <div v-else-if="cardmessage.jiantoutype === 2" class="zh-line"></div>
      </div>
      <div>{{ cardmessage.td }}</div>
    </div>
  </div>
</template>
<script>
import DocumentApi from "@/api/document";
import { blobToBase64 } from "@/utils/convert";
export default {
  props: {
    nowselectdataitemid: {
      type: Number,
      default: () => {
        return 0;
      }
    },
    nowcardmessage: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data () {
    return {
      cardmessage: {}
    };
  },
  watch: {
    nowselectdataitemid: {
      handler (newvalue, oldvalue) {
        this.nowselectdataitemid = newvalue;
      },
      deep: true
    },
    // var that = this
    nowcardmessage: {
      handler (newvalue, oldvalue) {
        this.cardmessage = {
          top: newvalue.yaxis,
          left: newvalue.xaxis,
          ta: newvalue.lastValue1.toFixed(2),
          unit: newvalue.unit || "",
          logoFileId: newvalue.logoFileId || "",
          tb: newvalue.collectDatetime.substring(5, 16),
          tc: newvalue.dataItemName,
          dataItemId: newvalue.dataItemId,
          td: newvalue.change.toString().substring(0, 5), // 百分比
          dataTypeId: newvalue.dataTypeId, // 环境数据类型
          jiantoutype: newvalue.status // 1上 3 下 2平
        };
        this.getimageurl(newvalue.logoFileId);
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    // 发挥背景图
    setbackimg () {
      if (this.nowselectdataitemid === this.cardmessage.dataItemId) {
        // return "background-color: #4896FC"; //  #FF6363 red || #F3A521 yellow
        return "background-color: #4896FC"
      }
    },
    getimageurl (id) {
      this.$set(this.cardmessage, "src", `${this.$baseurl.fileServiceUrl}base/files/preview?fileId=${id}`);
      // DocumentApi.fileDownload({ fileId: id }).then(res => {
      //   blobToBase64(res.data).then(res2 => {
      //     this.$set(this.cardmessage, "src", res2);
      //   });
      // });
    }
  }
};
</script>
<style lang="scss" scoped>
.animation {
  -webkit-animation: twinkling 1.8s infinite ease-in-out;
  animation: twinkling 1.8s infinite ease-in-out;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

.animation2 {
  -webkit-animation: twinkling 1.8s infinite ease-in-out;
  animation: twinkling 1.8s infinite ease-in-out;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

@keyframes twinkling {
  0% {
    opacity: 0.2;
    filter: alpha(opacity=40);
    -webkit-transform: scale(1);
  }
}

@-webkit-keyframes twinkling {
  0% {
    opacity: 0.2;
    filter: alpha(opacity=40);
    -webkit-transform: scale(1);
  }

  50% {
    opacity: 0.8;
    filter: alpha(opacity=90);
    -webkit-transform: scale(1.12);
  }

  100% {
    opacity: 0.2;
    filter: alpha(opacity=40);
    -webkit-transform: scale(1);
  }
}

.green-main {
  position: relative;
  width: 300px;
  height: 80px;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.9);
  color: #000;
  white-space: nowrap;
  text-align: center;
  white-space: nowrap;
  border-radius: 0 0 15px 15px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  cursor: pointer;

  .green-main-header {
    position: absolute;
    top: -20px;
    left: 0;
    width: 100%;
    height: 20px;
    border-radius: 15px 15px 0 0;
    background-color: rgba(255, 255, 255, 0.9);
  }

  &::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.9);
    top: -14px;
    left: 50%;
    z-index: 1;
    transform: translateX(-50%);
  }
}

.center-data {
  width: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
  margin-left: 10px;
  // border-left: #fff dashed 1px;
  border-right: #fff solid 1px;

  .data-one {
    font-size: 14px;
    line-height: 25px;
    font-weight: 700;
    white-space: nowrap;
  }

  .data-two {
    line-height: 20px;
    font-size: 13px;
    font-weight: 500;
    border-bottom: 1px solid #fff;
  }

  .data-three {
    width: 150px;
    font-size: 14px;
    font-weight: 700;
    color: #2E2E2E;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

.left-data {
  width: 40px;
  height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  white-space: pre-wrap;
  // margin-left: 25px;
  font-size: 14px;
  line-height: 21px;
  font-weight: 600;
}

.right-data {
  width: 30px;
  height: 80px;
  font-size: 14px;
  line-height: 10px;
  margin-left: 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-weight: 600;
}

.ani {
  animation: 0.1s linear infinite blink;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 25px;
  -webkit-animation: mymove 0.3s linear infinite blink;
}

@keyframes mymove {
  0% {
    color: #fff;
    background-color: #ddd;
  }

  50% {
    background-color: #ddd;
  }

  100% {
    color: #fff;
    background-color: rgb(209, 3, 3);
  }
}

.zh-line {
  border-top: 2px #fff solid;
  height: 10px;
  width: 10px;
  // background-color: #fff;
}

// .draw_share_atooltip {
//   background: #ddd !important;
// </style>
